package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.bairong.BairongPortraitCreditModelData;
import com.ucredit.babel.common.model.third.bairong.BairongPortraitCreditModelRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/*
 * 百融授信额度建议(定制版)
 *
 * @author:szw
 * */

public class BaiRongPortraitCreditModelParse extends ParseBase{
    private Text val = new Text();
    private Text key = new Text();

    /**
     * @param context
     * @param model
     * @param successful
     * @return
     * @throws IOException
     * @throws InterruptedException
     */

    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        BairongPortraitCreditModelRecord brRecord = (BairongPortraitCreditModelRecord) model;
        BairongPortraitCreditModelData brRecordData = brRecord.getData();

        StringBuilder sb = getBaseInfo(brRecord, successful);
        StringBuilder brSb = new StringBuilder(2000);

        brSb.append(brRecordData.getCode() == null ? "" : brRecordData.getCode()).append(CRT001);
        brSb.append(brRecordData.getSwiftNumber() == null ? "" : brRecordData.getSwiftNumber()).append(CRT001);
        brSb.append(brRecordData.getFlagCreditmodelevaC() == null ? "" : brRecordData.getFlagCreditmodelevaC()).append(CRT001);
        brSb.append(brRecordData.getCmecConservative() == null ? "" : brRecordData.getCmecConservative()).append(CRT001);
        brSb.append(brRecordData.getCmecRadical() == null ? "" : brRecordData.getCmecRadical()).append(CRT001);

        key.set(getKey());
        val.set((sb.toString() + brSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);

        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_br_portrait_credit_model_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.BAIRONG_PORTRAIT_CREDITMODEL_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "百融授信额度建议(定制版)";
    }
}
